package com.codes.service.impl;


import com.codes.core.common.enumtype.wordtpl.*;
import com.codes.dao.TemplateRefMapper;
import com.codes.service.TemplateRefSV;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 
 * @Date 2020/7/3 18:49
 * @Created  peanut
 */
@Service
@Slf4j
public class TemplateRefImpl implements TemplateRefSV {

    @Autowired
    private TemplateRefMapper templateRefMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return 0;
    }

    @Override
    public int insert(Map record) {
        return 0;
    }

    @Override
    public int  insertTemplateRef(Integer caseId,Integer tableId
              ,CaseTypeEnum caseTypeEnum
              ,TplTableMappingEnum tplTableMappingEnum,TplPersonTypeEnum tplPersonTypeEnum){
        // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
        Map<String,Object>  reMap = new HashMap(10);
        Integer caseType = caseTypeEnum.getCode(); // 案件类型
        Integer tableType = tplTableMappingEnum.getCode(); // 对应的表 对应的 模板
        Integer tplDetailType = tplPersonTypeEnum.getCode();    // 对应的详细模板类型   如 立案登记表个人  立案登记表企业
        // 获取模板信息
        reMap = getTpl(caseType,tableType,tplDetailType);
        reMap.put("caseId",caseId);
        reMap.put("tableType",tableType);
        reMap.put("tableId",tableId);
        reMap.put("caseType",caseType);


        return templateRefMapper.insertSelective(reMap);
    }

    // 根据案件类型  对应的表模板类型   详情模板类型   返回 对应的 文书信息
    private Map<String,Object> getTpl( Integer caseType, Integer tableType,Integer tplDetailType){
        Map<String,Object> reMap = new HashMap<>(10);
        TplWordEnum re = null; //  对应的文书模板详细信息
        boolean geren = tplDetailType == TplPersonTypeEnum.geren.getCode();
        switch (caseType){
            case 1  : //载质量
                log.info("载质量");
                switch (tableType){
                    case 1:  //    zhandianxinxi(1,"站点信息监测表"),
                        if(tplDetailType == TplPersonTypeEnum.zhedanghaopai.getCode()){
                            re = TplWordEnum.zaizhiliang6;// 站点信息监测表遮挡号牌
                        }else {
                            re = TplWordEnum.zaizhiliang5;// 站点信息监测表
                        }
                        break;
                    case 2:      //    liandengji(2,"立案登记表"),
                        if(geren){ // 个人
                            re = TplWordEnum.zaizhiliang3;
                        }else {
                            re = TplWordEnum.zaizhiliang4;  // 企业
                        }
                        break;
                    case 3:   //    chuliyijian(3,"案件处理意见"),
                        if(geren){
                            re = TplWordEnum.zaizhiliang1;
                        }else {
                            re = TplWordEnum.zaizhiliang2;
                        }
                        break;
                    case 4:     //    xunwenbilu(4,"询问笔录"),
                        if(tplDetailType == TplPersonTypeEnum.chezhufaren.getCode()) re = TplWordEnum.zaizhiliang10;
                        if(tplDetailType == TplPersonTypeEnum.daliren.getCode()) re = TplWordEnum.zaizhiliang09;
                        if(tplDetailType == TplPersonTypeEnum.jiahsiyuan.getCode()) re = TplWordEnum.zaizhiliang11;
                        break;
                    case 5:     //    weifaxingwei(5,"违法行为通知"),
                        re = TplWordEnum.zaizhiliang12;
                        break;
                    case 6:   //    songdahuizheng(6,"送达回证"),
                        re = TplWordEnum.zaizhiliang13;
                        break;
                    case 7:   //    chenshu(7,"陈述申辩"),
                        re = TplWordEnum.zaizhiliang14;
                        break;
                    case 8:   //    jieanbaogao(8,"结案报告"),
                        if(geren) re = TplWordEnum.zaizhiliang7;
                        if(!geren) re = TplWordEnum.zaizhiliang8;
                        break;
                    default:
                        break;
                }
                break;
            case 2 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("几何超限");
                switch (tableType){
                    case 1:  //    zhandianxinxi(1,"站点信息监测表"),
                        if(tplDetailType == TplPersonTypeEnum.zhedanghaopai.getCode()){
                            re = TplWordEnum.zaizhiliang6;// 站点信息监测表遮挡号牌
                        }else {
                            re = TplWordEnum.zaizhiliang5;// 站点信息监测表
                        }
                        break;
                    case 2:      //    liandengji(2,"立案登记表"),
                        if(geren){ // 个人
                            re = TplWordEnum.zaizhiliang3;
                        }else {
                            re = TplWordEnum.zaizhiliang4;  // 企业
                        }
                        break;
                    case 3:   //    chuliyijian(3,"案件处理意见"),
                        if(geren){
                            re = TplWordEnum.zaizhiliang1;
                        }else {
                            re = TplWordEnum.zaizhiliang2;
                        }
                        break;
                    case 4:     //    xunwenbilu(4,"询问笔录"),
                        if(tplDetailType == TplPersonTypeEnum.chezhufaren.getCode()) re = TplWordEnum.zaizhiliang10;
                        if(tplDetailType == TplPersonTypeEnum.daliren.getCode()) re = TplWordEnum.zaizhiliang09;
                        if(tplDetailType == TplPersonTypeEnum.jiahsiyuan.getCode()) re = TplWordEnum.zaizhiliang11;
                        break;
                    case 5:     //    weifaxingwei(5,"违法行为通知"),
                        re = TplWordEnum.zaizhiliang12;
                        break;
                    case 6:   //    songdahuizheng(6,"送达回证"),
                        re = TplWordEnum.zaizhiliang13;
                        break;
                    case 7:   //    chenshu(7,"陈述申辩"),
                        re = TplWordEnum.zaizhiliang14;
                        break;
                    case 8:   //    jieanbaogao(8,"结案报告"),
                        if(geren) re = TplWordEnum.zaizhiliang7;
                        if(!geren) re = TplWordEnum.zaizhiliang8;
                        break;
                    default:
                        break;
                }
                break;
            case 3 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("年检");
                break;
            case 4 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("动态监控");
                break;
            case 5 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("改装");
                break;
            case 6 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("环保");
                break;
            case 7 :   // 案件类型 1载质量2几何3年检4动态监控5改装6.环保7线路',
                log.info("路线");
                break;
            default:
                break;
        }

        //  返回 模板信息
        Integer templateId = re.getCode();
        String templateName = re.getLabel();
        reMap.put("templateId",templateId);
        reMap.put("templateName",templateName);
        return reMap;
        // end
    }

    @Override
    public int insertSelective(Map record) {


        Integer templateId = null;

        //   表类型  如 立案登记表
       // Integer tableType = TemplateWordEnum.zaizhiliang5.getCode();
        //   登记 人 类型  个人   企业
       // TemplateWordEnum t = TemplateWordEnum.zaizhiliang3;
        return templateRefMapper.insertSelective(record);
    }

    @Override
    public Map selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(Map record) {
        return templateRefMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Map record) {
        return 0;
    }

    @Override
    public List<Map<String, Object>> getList(Map map) {
        return templateRefMapper.getList(map);
    }
}